<template>


	<view class="content">
		<view v-if="error"> 参数错误，请重新扫描二维码进入 </view>
		<view v-if="!error">
			<view class="list-item">
				姓名：<input v-model="realName" class="input" />
			</view>
			<view class="list-item">
				手机：<input v-model="phone" class="input" /></view>
			<view class="list-item">
				住址：<input v-model="address" class="input" /></view>
			<button type="primary" @click="submit">修改</button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				realName: '',
				phone: '',
				address: '',
				error: true,
				id: ''
			}
		},
		onLoad(params) {
			let p = JSON.parse(params.p);
			console.log(p)
			let u = uni.getStorageSync("userinfo");
			this.realName = u.realName;
			this.phone = u.phone;
			this.address = u.address;
			this.id = p.id;
			if (p.id) {
				this.error = false;
			}
		},
		methods: {
			submit() {
				let that = this;
				uni.showModal({
					title: '提示',
					content: '确认提交？',
					success: function(res) {
						if (res.confirm) {
							let p = {
								id: that.id,
								realName: that.realName,
								phone: that.phone,
								address: that.address
							}
							console.log(p)
							that.$sendhttp("/Weixin/modifyUser.dhtml", p, function(data) {
								let u = uni.getStorageSync("userinfo");
								u.realName = that.realName;
								u.phone = that.phone;
								u.address = that.address;
								uni.setStorageSync("userinfo", u);
								that.$showModal("修改成功");
								uni.navigateBack({})
							});
						}
					}
				});
			}
		}
	}
</script>

<style>
	page {
		background: #fff;
	}

	.title {
		color: #007AFF;
		font-size: 21px;
		font-weight: 700;
		display: flex;
		justify-content: center;
		margin: 20rpx 10px;
	}

	.list-item,
	.list-item-no,
	.list-item-mul {
		display: flex;
		justify-content: space-between;
		border: 1px solid lightgray;
		line-height: 50px;
		margin: 20px 20px;
		padding: 0 10px;
	}

	.list-item-no {
		border: none;
		margin-bottom: -30px;
		font-weight: 700;
		font-size: 21px;
	}

	.list-item-mul {
		line-height: 30px;
		padding: 10px;
		flex-direction: column;
	}

	.list-item-col {
		line-height: 30px;
		padding: 10px;
		flex-direction: column;
	}

	.uni-radio-group {
		display: flex;
		flex-direction: column;
		justify-content: space-around;
	}

	.uni-radio-group-col {
		display: flex;
		flex-direction: column;
		justify-content: space-around;
	}

	.uni-list-cell {
		flex-direction: row;
		display: flex;
	}

	.input {
		width: 250px;
		height: 50px;
	}
</style>
